package com.training.api.repository;

import com.training.bean.LearningTrackData;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface LearningTrackDataRepository extends JpaRepository<LearningTrackData, Integer> {
    
    /**
     * 根据用户ID和课程内容ID查找学习记录
     */
    @Query("SELECT l FROM LearningTrackData l WHERE l.uid = :uid AND l.ccid = :ccid")
    List<LearningTrackData> findByUidAndCcid(@Param("uid") int uid, @Param("ccid") int ccid);
    
    /**
     * 根据用户ID和课程内容ID删除旧的学习记录
     */
    @Modifying
    @Transactional
    @Query("DELETE FROM LearningTrackData l WHERE l.uid = :uid AND l.ccid = :ccid")
    void deleteByUidAndCcid(@Param("uid") int uid, @Param("ccid") int ccid);
}